<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>支付二维码</title>
    <script type="text/javascript" src="./js/qrcode.js"></script> <!-- 引入QRCode库 -->
</head>
<body>
<h2>微信扫码支付</h2>
<div id="qrcode"></div>
<script>
    var qrcode = new QRCode(document.getElementById("qrcode"), {
        width : 100,
        height : 100
    });
    let paymentUrl = ''; // 存储支付URL
    // 监听SSE消息
    const eventSource = new EventSource('/user/prePayUrl/sse');
    eventSource.onmessage = function (event) {
        const data = event.data;
        paymentUrl = data; // 获取支付URL
        console.log("预支付url：" + paymentUrl.replaceAll("\"", ""));

        // 更新二维码
        if (paymentUrl) {
            qrcode.makeCode(paymentUrl.replaceAll("\"", ""));
        }
    };
</script>
</body>
</html>
